<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="UTF-8"%>  
<%@ page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="cn.ainit.sys.utils.DateTimeStr"%>   
<%@page import="cn.ainit.sys.framework.upload.*"%>  
<%@page import="cn.ainit.common.SpringContextTool"%>  
<%@page import="javax.servlet.*"%>
    <%  
    	System.out.print("附件上传功能..........");
    	UploadController uploadController = (UploadController) SpringContextTool.getApplicationContext().getBean("uploadController");;
        //新建一个SmartUpload对象      
        SmartUpload su = new SmartUpload();  
       // su.initialize(this.getServletConfig(),request,response);//初始化类，    
        boolean sign = true;      
        String info = "";
        String fileName = null;
        try {      
	        //上传初始化      
	        request.setCharacterEncoding("UTF-8");
	     	//su.initialize(pageContext);      
	     	su.initialize(config,request,response);      
	        // 设定上传限制      
	        //1.限制每个上传文件的最大长度。      
	        su.setMaxFileSize(10000000);
	       
	        //2.限制总上传数据的长度。      
	        su.setTotalMaxFileSize(20000000);      
	         
	        //3.设定允许上传的文件（通过扩展名限制）,仅允许doc,txt文件。      
	        su.setAllowedFilesList("doc,txt,jpg,rar,mid,waw,mp3,gif,png,jpeg,xls,docx,xlsx");      
	              
	        //4.设定禁止上传的文件（通过扩展名限制）,禁止上传带有exe,bat,jsp,htm,html扩展名的文件和没有扩展名的文件。      
	        su.setDeniedFilesList("exe,bat,jsp,htm,html");      
	     
	        //上传文件 
	        su.upload();
	        
	        //修改文件名
	       	fileName = DateTimeStr.formatDateStrLong()+"."+su.getFiles().getFile(0).getFileExt();
	       	
	        //将上传文件保存到指定目录 
	        su.getFiles().getFile(0).saveAs("/UploadFiles/additional/"+fileName);     
	        //su.getFiles().getFile(0).saveAs("XXXXXXXXXXXXX.jpg");
	        
	        //获取单个参数 保存到数据库
	        request.setAttribute("ufileName",su.getRequest().getParameter("ufileName"));//获取用户定义的文件名
	        request.setAttribute("path","/UploadFiles/additional/"+fileName);
	        request.setAttribute("suffix",su.getFiles().getFile(0).getFileExt());
	    	uploadController.upFiles(request,session,response);
	    	sign = true;
        } catch (Exception e) {     
            e.printStackTrace();
            info = e.getMessage();
            sign = false;     
        }
        if(sign)
        {   
        	String content = "所有附件列表";
            out.println("<script>parent.upImagemCback('1','"+request.getParameter("formId")+"','"+request.getParameter("pkValue")+"','"+request.getParameter("dsId")+"','"+request.getParameter("clnName")+"','"+content+"')</script>");     
        	System.out.print("Success");
        }else     
        {
        	String content = "所有附件列表";
        	System.out.print("Fail");
           	out.println("<script>parent.upImagemCback('2','"+request.getParameter("formId")+"','"+request.getParameter("pkValue")+"','"+request.getParameter("dsId")+"','"+request.getParameter("clnName")+"','"+content+"')</script>");     
        }
    %> 